#include <iostream>
#include <cstring>

using namespace std;

const int N = 10;

int T, n, m;
int grid[N][N];
int visit[N][N];
int ans, sum;
int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};

void dfs(int cur_x, int cur_y)
{
	if(cur_y > m)
	{
		cur_y = 1; cur_x++;
	}
	if(cur_x > n)
	{
		ans = max(ans, sum);
		return;
	}
	
	// buxuan
	dfs(cur_x, cur_y + 1);
	
	// ѡ
	if(visit[cur_x][cur_y] > 0) dfs(cur_x, cur_y + 1);
	else
	{
		visit[cur_x][cur_y]++;
		sum += grid[cur_x][cur_y];
		for(int k = 0; k < 8; k++) 
		{
			int next_x = cur_x + dx[k];
			int next_y = cur_y + dy[k];
			if(next_x < 1 || next_y < 1 || next_x > n || next_y > m) continue;
			visit[next_x][next_y]++;
		}
		
		dfs(cur_x, cur_y + 1);
		
		visit[cur_x][cur_y]--;
		sum -= grid[cur_x][cur_y];
		for(int k = 0; k < 8; k++) 
		{
			int next_x = cur_x + dx[k];
			int next_y = cur_y + dy[k];
			if(next_x < 1 || next_y < 1 || next_x > n || next_y > m) continue;
			visit[next_x][next_y]--;
		}
		
	}

}

int main()
{
	cin >> T;
	while(T--)
	{
		sum = ans = 0;
		memset(visit, 0, sizeof visit);
		cin >> n >> m;
		for(int i =1; i <= n; i++)
		{
			for(int j =1; j <= m; j++)
			{
				cin >> grid[i][j];
			}
		}
		dfs(1, 1);
		cout << ans << endl;
	}
	return 0;
}
